/*     */ package com.infoservice.schedule.generator;
/*     */ 
/*     */ import com.infoservice.po3.POFactory;
/*     */ import com.infoservice.po3.POFactoryBuilder;
/*     */ import com.infoservice.po3.core.context.POContext;
/*     */ import com.infoservice.po3.core.exceptions.DAOException;
/*     */ import com.infoservice.schedule.Constant;
/*     */ import com.infoservice.schedule.po.pos.TaskPO;
/*     */ import com.infoservice.schedule.util.TaskUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class GenHourTask extends TaskGenerator
/*     */ {
/*     */   public GenHourTask(TaskPlanInfo tpInfo, TaskPO tk)
/*     */   {
/*  41 */     super(tpInfo, tk);
/*     */   }
/*     */ 
/*     */   public void fixTask()
/*     */   {
/*     */   }
/*     */ 
/*     */   public long getDelayTime()
/*     */   {
/*  58 */     Date nextTime = getNextExcTime();
/*  59 */     Calendar cur = TaskUtils.getCalendar();
/*  60 */     return nextTime.getTime() - cur.getTimeInMillis() < Constant.TASK_GEN_AHEAD_TIME ? 0L : nextTime.getTime() - cur.getTimeInMillis() - Constant.TASK_GEN_AHEAD_TIME;
/*     */   }
/*     */ 
/*     */   public Date getNextExcTime()
/*     */   {
/*  67 */     Calendar cur = TaskUtils.getCalendar();
/*  68 */     Date planStartTime = null;
/*  69 */     if (this.tk != null) {
/*  70 */       planStartTime = this.tk.getPlanStartTime();
/*     */     } else {
/*  72 */       Calendar start = TaskUtils.getCalendar();
/*  73 */       String[] temp = this.tpInfo.getPlanStart().split(":");
/*  74 */       start.set(11, Integer.parseInt(temp[0]));
/*  75 */       start.set(12, Integer.parseInt(temp[1]));
/*  76 */       Date endDate = getEndDate();
/*  77 */       if ((start.getTimeInMillis() >= endDate.getTime()) && (start.getTimeInMillis() >= cur.getTimeInMillis())) {
/*  78 */         start.setTimeInMillis(start.getTimeInMillis() - 86400000L);
/*     */       }
/*  80 */       planStartTime = start.getTime();
/*     */     }
/*  82 */     if (planStartTime.getTime() >= cur.getTimeInMillis())
/*  83 */       return planStartTime;
/*  84 */     long times = (cur.getTimeInMillis() - planStartTime.getTime()) / getInterval();
/*  85 */     times += 1L;
/*  86 */     return new Date(planStartTime.getTime() + times * getInterval());
/*     */   }
/*     */ 
/*     */   public long getPeriodTime() {
/*  90 */     return getInterval();
/*     */   }
/*     */ 
/*     */   public long getInterval() {
/*  94 */     return this.tpInfo.getTaskInterval().intValue() * 60 * 60 * 1000;
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/* 102 */     genTask();
/*     */   }
/*     */   public void genTask() {
/* 105 */     Date planStartDate = getNextExcTime();
/* 106 */     if (!TaskUtils.checkTimeRange(planStartDate, this.tpInfo.getPlanStart(), this.tpInfo.getPlanEnd()))
/* 107 */       return;
/*     */     try
/*     */     {
/* 110 */       POFactory factory = POFactoryBuilder.getInstance();
/* 111 */       TaskPO taskpo = new TaskPO();
/* 112 */       taskpo.setTaskId(this.tpInfo.getTaskId());
/* 113 */       taskpo.setPlanId(this.tpInfo.getPlanId());
/* 114 */       taskpo.setRunType(Integer.valueOf(-1));
/* 115 */       taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/* 116 */       taskpo.setMarker(Integer.valueOf(0));
/* 117 */       taskpo.setExecuteType(this.tpInfo.getTaskManual());
/* 118 */       taskpo.setP1value(this.tpInfo.getP1value());
/* 119 */       taskpo.setP2value(this.tpInfo.getP2value());
/* 120 */       taskpo.setP3value(this.tpInfo.getP3value());
/* 121 */       taskpo.setP4value(this.tpInfo.getP4value());
/* 122 */       taskpo.setP5value(this.tpInfo.getP5value());
/* 123 */       Date planStartTime = getNextExcTime();
/* 124 */       taskpo.setPlanStartTime(planStartTime);
/* 125 */       taskpo.setLogId(factory.getLongPK(taskpo));
/* 126 */       factory.insert(taskpo);
/* 127 */       POContext.endTxn(true);
/* 128 */       this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartTime));
/* 129 */       setTaskPO(planStartTime);
/*     */     } catch (DAOException e) {
/* 131 */       if ((e.getCause() instanceof SQLException)) {
/* 132 */         SQLException sqlE = (SQLException)e.getCause();
/* 133 */         if ((sqlE.getErrorCode() == 1) && (sqlE.getMessage().indexOf("ORA-00001") != -1)) {
/* 134 */           this.logger.error(e.getMessage(), e);
/*     */         }
/*     */       }
/* 137 */       POContext.endTxn(false);
/*     */     } catch (Exception e) {
/* 139 */       this.logger.error(e.getMessage(), e);
/* 140 */       POContext.endTxn(false);
/*     */     } finally {
/* 142 */       POContext.cleanTxn();
/*     */     }
/*     */   }
/*     */ 
/*     */   public Date getEndDate()
/*     */   {
/* 152 */     Calendar cur = TaskUtils.getCalendar();
/* 153 */     String[] end = this.tpInfo.getPlanEnd().split(":");
/* 154 */     cur.set(11, Integer.parseInt(end[0]));
/* 155 */     cur.set(12, Integer.parseInt(end[1]));
/* 156 */     return cur.getTime();
/*     */   }
/*     */   public Date getStartDate() {
/* 159 */     Calendar cur = TaskUtils.getCalendar();
/* 160 */     String[] end = this.tpInfo.getPlanStart().split(":");
/* 161 */     cur.set(11, Integer.parseInt(end[0]));
/* 162 */     cur.set(12, Integer.parseInt(end[1]));
/* 163 */     return cur.getTime();
/*     */   }
/*     */ 
/*     */   public void removeTaskPlan()
/*     */   {
/* 170 */     cancel();
/*     */   }
/*     */ 
/*     */   public int getIgnoreTimes()
/*     */   {
/* 179 */     return 0;
/*     */   }
/*     */ 
/*     */   public void setTaskPO(Date planStartTime)
/*     */   {
/* 187 */     if (this.tk == null) {
/* 188 */       this.tk = new TaskPO();
/*     */     }
/* 190 */     this.tk.setPlanStartTime(planStartTime);
/*     */   }
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.generator.GenHourTask
 * JD-Core Version:    0.6.0
 */